<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
 
<div style="margin:20px 0;"></div>
<div class="easyui-panel" >
	<div style="padding:10px 60px 20px 60px">
    <form id="chnhitchForm"  name="chnhitchForm" method="post" >
    	<input type="hidden" id="chnhitch_uuid" name="chnhitch_uuid" value="${infChnhitch.chnhitch_uuid}"/>
    	<input type="hidden" id="ins_uuid" name="ins_uuid" value="${infChnhitch.ins_uuid}"/>
    	<input type="hidden" id="area_uuid" name="area_uuid" value="${infChnhitch.area_uuid}"/>
    	<input type="hidden" id="service_uuid" name="service_uuid" value="${infChnhitch.service_uuid}"/>
    	<input type="hidden" id="service_param_uuid" name="service_param_uuid" value="${infChnhitch.service_param_uuid}"/>
    	<input type="hidden" id="crd_ins" name="crd_ins" value="${infChnhitch.crd_ins}"/>
    	<input type="hidden" id="crd_bin" name="crd_bin" value="${infChnhitch.crd_bin}"/>
    	<input type="hidden" id="channel_grp_uuid" name="channel_grp_uuid" value="${infChnhitch.channel_grp_uuid}"/>
    	<input type="hidden" id="hitch_service_uuid" name="hitch_service_uuid" value="${infChnhitch.hitch_service_uuid}"/>
    	<input type="hidden" id="hitch_service_param_uuid" name="hitch_service_param_uuid" value="${infChnhitch.hitch_service_param_uuid}"/>
    	<table cellpadding="5" style="width:100%">
    		<tr>
    			<td>所属机构:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="insname" value="${infChnhitch.insname}" data-options="required:true"/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctinsname">选择</a></td>
    			<td>所属地区:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="areaname" value="${infChnhitch.areaname}" data-options=""/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctarea">选择</a>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-clear" id="cleararea">清除</a></td>      	     			
    		</tr>    		
    		<tr>
    			<td>业务名称:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="sername" value="${infChnhitch.sername}" data-options="required:true"/>
    			</td> 
    			<td>业务参数名称:</td>
    			<td><input class="easyui-textbox" type="text" name="purname" readonly="readonly" id="purname" data-options="required:true" value="${infChnhitch.purname }"></input>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctsername">选择</a></td>      	     			
    		</tr>   		
    		<tr>
    			<td>卡bin:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="cardbin" value="${infChnhitch.cardbin}" data-options=""/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctcardbin">选择</a>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-clear" id="clearcardbin">清除</a></td>
    			<td>发卡行:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="cardins" value="${infChnhitch.cardins}" data-options=""/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctcardins">选择</a>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-clear" id="clearcardins">清除</a></td>    			   	     			      	     			
    		</tr>   		
    		<tr>   
    			<td>卡介质:</td>
		    	<td><code:codeSelect id="crd_medium" name="crd_medium" code_type="crd_medium" showSelect="true" selectId="${infChnhitch.crd_medium}"></code:codeSelect>	</td> 			
    			<td>卡性质:</td>
		    	<td><code:codeSelect id="crd_nature" name="crd_nature" code_type="crd_nature" showSelect="true" selectId="${infChnhitch.crd_nature}"></code:codeSelect> </td> 		    	  	     			  	     			   			    	     			
    		</tr>    		    
    		<tr>
    			<td>最小交易金额(元):</td>
    			<td><input class="easyui-textbox" type="text" id="min_amt" name="min_amt" data-options="required:true,validType:['checkminamt']" value="${infChnhitch.min_amt }"></input></td>
    			<td>最大交易金额(元):</td>
    			<td><input class="easyui-textbox" type="text" id="max_amt" name="max_amt" data-options="required:true,validType:['checkmaxamt']" value="${infChnhitch.max_amt }"></input></td>    			    	     			
    		</tr>  	    		
    		<tr>
    			<td>套扣业务:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="hsername" value="${infChnhitch.hsername}" data-options="required:true"/>
    			</td>  
    			<td>套扣业务参数:</td>
    			<td><input class="easyui-textbox" type="text" name="hpurname" id="hpurname" readonly="readonly" data-options="required:true" value="${infChnhitch.hpurname }"></input>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelcthsername">选择</a></td>    			      	     			
    		</tr>	  
    		<tr>    			
    			<td>所属通道组别:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="chngrpname" value="${infChnhitch.chngrpname}" data-options="required:true"/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctchngrp">选择</a></td>     	     			
    		</tr>	 		 		  		    		 
    	</table>
    
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-save" id="saveBtn">保存</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
	    </div>
    </form>
    </div>
</div>
<div id="commonTree">
	<div id="ztreeObj" class="ztree"></div>
</div>

<div id="dialogChnGrp" >
	<div style="padding:3px" class="easyui-panel datagrid-toolbar">
		<div>
			<span>通道组别编号:</span>
			<input id="channel_grp" type="text" name="channel_grp"  class="easyui-textbox"  >					
		 	<a href="#" class="easyui-linkbutton btn"   onclick="chnGrpSearch() ">查询</a>
		 	<a href="#" class="easyui-linkbutton btn" onclick="resetParam() ">重置</a>
		</div>	 
	</div>
    <table id="tableChnGrp">			 
	</table>
	
</div>
<div id="dialogCardBin" >
	<div style="padding:3px" class="easyui-panel datagrid-toolbar">
		<div>
			<span>卡bin:</span>
			<input id="card_bin" type="text" name="card_bin"  class="easyui-textbox"  >					
		 	<a href="#" class="easyui-linkbutton btn"   onclick="cardSearch() ">查询</a>
		 	<a href="#" class="easyui-linkbutton btn" onclick="resetParam() ">重置</a>
		</div>	 
	</div>
    <table id="tableCardBin">			 
	</table>
	
</div>
<div id="dialogCardIns" >
	<div style="padding:3px" class="easyui-panel datagrid-toolbar">
		<div>
			<span>总行行号:</span>
			<input id="super_bank_no"  name="super_bank_no"  class="easyui-textbox"  >					
		 	<a href="#" class="easyui-linkbutton btn"   onclick="cardInsSearch() ">查询</a>
		 	<a href="#" class="easyui-linkbutton btn" onclick="resetParam() ">重置</a>
		</div>	 
	</div>
    <table id="tableCardIns">			 
	</table>
	
</div>
<script>
$(document).ready(function() {
	$("#dialogCardBin").attr("style", "display: none;");
	$("#dialogCardIns").attr("style", "display: none;");
	$("#dialogChnGrp").attr("style", "display: none;");
	$.extend($.fn.textbox.defaults.rules, {
		checkminamt: {     
            validator: function(value){                                
                 return /^(?=([0-9]{1,10}$|[0-9]{1,10}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);  
            },     
            message: '最小交易金额格式不符或长度超限'     
        },
        checkmaxamt: {     
            validator: function(value){                                 
                 return /^(?=([0-9]{1,10}$|[0-9]{1,10}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);  
            },     
            message: '最大交易金额格式不符或长度超限'     
        }       
	});
	var commonTree;
	
	var setting = {
			callback:{
				onClick: zTreeOnClick
			},
			data:{				
				simpleData:{enable: true}
			}
		}
	function zTreeOnClick(event, treeId, treeNode) {
		if(treeNode.flag!="p"){
			$.jpmessage.info('只能选择业务参数!');
			return;
		}	    
	};
	/*选择机构*/
	$("#selelctinsname").click(function(){
		commonTree = showInsTree(insselected, null,null);				
	})
	/*选择地区*/
	$("#selelctarea").click(function(){
		showAreaTree(areaselected);			
	});
	/*选择业务参数*/
	$("#selelctsername").click(function(){
		openTree("../serviceInf/getServiceInfTree.do","选择业务参数",serselected,setting);		
	})
	
	$("#selelcthsername").click(function(){
		openTree("../serviceInf/getServiceInfTree.do","选择业务参数",hserselected,setting);		
	})
	
	function insselected(){
		var nodes = commonTree.getSelectedNodes();
		if(nodes && nodes.length > 0){
			$("#ins_uuid").val(nodes[0].ID);
			$("#insname").textbox("setValue", nodes[0].NAME);		
		}
	}
	function areaselected(nodes){		
		if(nodes && nodes.length > 0){
			$("#area_uuid").val(nodes[0].uuid);
			$("#areaname").textbox("setValue", nodes[0].NAME);		
		}
	}
	function serselected(){
		var nodes = commonTree.getSelectedNodes();
		if(nodes && nodes.length > 0){
			$("#service_uuid").val(nodes[0].getParentNode().id);
			$("#service_param_uuid").val(nodes[0].id);
			$("#purname").textbox("setValue", nodes[0].name);		
			$("#sername").textbox("setValue", nodes[0].getParentNode().name);
		}
	}
	function hserselected(){
		var nodes = commonTree.getSelectedNodes();
		if(nodes && nodes.length > 0){
			$("#hitch_service_uuid").val(nodes[0].getParentNode().id);
			$("#hitch_service_param_uuid").val(nodes[0].id);
			$("#hpurname").textbox("setValue", nodes[0].name);		
			$("#hsername").textbox("setValue", nodes[0].getParentNode().name);
		}
	}
	/*选择通道组别*/
	var hnGrpGrid;
	$("#selelctchngrp").click(function(){
		chnGrpGrid = $("#tableChnGrp").jpgrid({
			url: "../channelgrp/getChannelGrpListJson.do",
			columns: [
						{title: "通道组别编号", field: "CHANNEL_GRP",width:100},
						{title: "通道组别描述", field: "DESCPT"}												
					]
		});
		openModal("#dialogChnGrp", {width:800, height:400,title:"选择通道组别"}, saveChnGrp);
		
	})
	/*选择卡bin*/
	var cardBinGrid;
	$("#selelctcardbin").click(function(){
		cardBinGrid = $("#tableCardBin").jpgrid({
			url: "../cardbin/getCardBinListJson.do",
			columns: [
						{title: "卡bin", field: "CARD_BIN",width:100},
						{title: "卡名称", field: "CARD_NAME",width:100},
						{title: "发卡机构代码", field: "CARD_INS_CD"},
						{title: "发卡机构名称", field: "CARD_INS_NM"}
					]
		});
		openModal("#dialogCardBin", {width:800, height:400,title:"选择卡bin"}, saveCardBin);
		
	})
	/*选择发卡行*/
	var cardinsGrid;
	$("#selelctcardins").click(function(){
		cardinsGrid = $("#tableCardIns").jpgrid({
			url: "../superbank/getSuperBankListJson.do",
			columns: [
						{title: "总行行号", field: "SUPER_BANK_NO"},
						{title: "银行名称", field: "BANK_NM"},
						{title: "银行地址", field: "BANK_ADDR"}
					]
		});
		openModal("#dialogCardIns", {width:800, height:400,title:"选择发卡行"}, saveCardIns);
	})
	/*清除卡bin*/
	$("#clearcardbin").click(function(){
		$("#crd_bin").val("");
		$("#cardbin").textbox("setValue", "");
	})
	/*清除地区*/
	$("#cleararea").click(function(){
		$("#area_uuid").val("");
		$("#areaname").textbox("setValue", "");
	})
	/*清除发卡行*/
	$("#clearcardins").click(function(){
		$("#crd_ins").val("");
		$("#cardins").textbox("setValue", "");
	})
	
	
	function openTree(url,title,callback,setting){
		$.ajax({
			url: url,
			async: false,
			success: function(result){
				commonTree=$.fn.zTree.init($("#ztreeObj"), setting, result);
				//commonTree.expandNode(commonTree.getNodesByFilter(function (node) { return node.level == 0 }, true), true, false, true);
			}
		});
		openModal("#commonTree", {width:400, height:400,title:title}, callback);
	}
	
	$("#saveBtn").click(function(){	
		if($("#chnhitchForm").form("validate")){	
			if($("#min_amt").val() != null && $("#min_amt").val() != "" 
	            && $("#max_amt").val()!=null && $("#max_amt").val()!="" 
	            && parseFloat($("#min_amt").val()) > parseFloat($("#max_amt").val())){
	            $.jpmessage.info('最小交易金额不应大于最大交易金额');
	            return;
	        }			
			//表单提交的方法、比如ajax提交
	    	  $("#chnhitchForm").attr("action","../chnhitchinf/saveChnhitchInf.do?");
	    	  document.getElementById("chnhitchForm").submit(); 
		}
		
	});
	$("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#saveBtn').click();
        }
    });
})

function resetParam(){		
	$("#channel_grp").textbox("setValue", "");		
	$("#card_bin").textbox("setValue", "");
	$("#super_bank_no").textbox("setValue", "");
}
	
function chnGrpSearch() {	 
	chnGrpGrid.load({
		channel_grp: $('#channel_grp').val();
	});
}
 
function cardSearch() {	 
	cardBinGrid.load({
		card_bin: $('#card_bin').val();					
	});
}  
function cardInsSearch() {	 
	cardinsGrid.load({
		super_bank_no: $('#super_bank_no').val();
	});
} 

function saveChnGrp(){
	return commonsave("tableChnGrp","channel_grp_uuid","chngrpname","dialogChnGrp");	
}

function saveCardBin(){
	return commonsave("tableCardBin","crd_bin","cardbin","dialogCardBin");	
}
function saveCardIns(){
	return commonsave("tableCardIns","crd_ins","cardins","dialogCardIns");	
}
function commonsave(tableid,id,name,dialog){
	var rows = $('#'+tableid).datagrid('getSelections');
	if(rows.length==0){
		$.jpmessage.warning('请至少选择一条记录!');
		return false;
	}
	if(rows.length>1){
		$.jpmessage.warning('只能选择一条记录!');
		return false;
	}
	if("crd_bin"==id){
		$("#"+id).val(rows[0].CARD_BIN);
	}else if("crd_ins"==id){
		$("#"+id).val(rows[0].SUPER_BANK_NO);
	}else{		
		$("#"+id).val(rows[0].UUID);
	}
	if("chngrpname"==name){						
		$("#chngrpname").textbox("setValue", rows[0].CHANNEL_GRP+"-"+rows[0].DESCPT);
	}
	
	if("cardbin"==name){				
		$("#cardbin").textbox("setValue", rows[0].CARD_BIN+"-"+rows[0].CARD_NAME+"-"+rows[0].CARD_INS_NM);
	}
	if("cardins"==name){				
		$("#cardins").textbox("setValue", rows[0].SUPER_BANK_NO+"-"+rows[0].BANK_NM);
	}
	return;
}
</script>